package cool.taomu.software.fig.asm.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cool.taomu.software.fig.asm.aspect2.AspectHandle;
import cool.taomu.software.fig.asm.aspect2.AspectUtils;
import cool.taomu.software.fig.asm.utils.ClassToBytecode;
import cool.taomu.software.fig.objectpool.ObjectPool;
import cool.taomu.software.fig.objectpool.ObjectPoolFactory;

public class AspectTest2 {
	public static class Dest {
		public void print(String msg) {
			System.out.println("我是dest的print方法");
		}
	}

	public static class Aspect {
		public void handle(AspectHandle ah) {
			if (ah.getArguments()[0].equals("Hello World")) {
				System.out.println("我是Aspect的handle方法");
			} else {
				ah.invoke();
			}
		}
	}

	public static class FigAspect_a1b22849a2d54e3388d9b21f9539e1e3 extends Dest {
		private static Logger LOG = LoggerFactory.getLogger(FigAspect_a1b22849a2d54e3388d9b21f9539e1e3.class);

		public void print(String var1) {
			try {
				try (ObjectPool<Aspect> pool = ObjectPoolFactory.borrowObject(Aspect.class)) {
					Aspect var2 = pool.getInstance();
					AspectHandle var3 = new AspectHandle();
					var3.setArguments(new Object[] { var1 });
					var3.setMethod(Dest.class.getDeclaredMethod("print", String.class));
					try (ObjectPool<Dest> destPool = ObjectPoolFactory.borrowObject(Dest.class)) {
						Dest var6 = destPool.getInstance();
						var3.setInstance(var6);
						var2.handle(var3);
					}
				}
			} catch (Exception ex) {
				LOG.info("Exception : {}", ex);
			}
		}
	}

	public static void a() throws InstantiationException, IllegalAccessException {
		Class<?> cl = AspectUtils.getInstance().aspect(Dest.class, Aspect.class, "handle");
		Dest dest = (Dest) cl.newInstance();
		dest.print("Hello World");
	}

	public static void main(String[] args) throws InstantiationException, IllegalAccessException {
		//a();
		//
		ClassToBytecode.toBytecode(FigAspect_a1b22849a2d54e3388d9b21f9539e1e3.class);
	}
}
